<template>
  <view class="definite">
    <u-navbar :is-back="true" title="分润明细" back-text=""> </u-navbar>
    <view style="padding: 1rem; background: #ffffff; margin-bottom: 0.2rem">
      <!-- <view class="image">
        <image
          @click="goSettingM"
          src="../../../style/image/my/A29.png"
          alt=""
        />
        <span style="font-size: 0.65rem; color: #000000">2019.10.09</span>
      </view> -->
      <view style="display: flex; justify-content: center; align-items: center">
        <timeTest :selectTime="selectTime" @func="getMsgFormSon"></timeTest>
      </view>
      <view class="money">{{ proily }}</view>
      <view class="time">总收益(元)</view>
    </view>
    <view class="record">
      <span>收益时间</span>
      <span style="float: right">收益金额(元)</span>
    </view>

    <u-empty
      style="margin-top: 0rem"
      v-if="showDatas.length == 0"
      text="暂无数据"
      mode="data"
    ></u-empty>

    <view v-if="showDatas.length != 0">
      <view class="item" v-for="(item, index) in showDatas" :key="index">
        <span class="item-one">2019.10.09 11:18:27</span>
        <span class="item-two">9878.00</span>
      </view>
      <u-loadmore
        v-show="loadmoreModal"
        :status="status"
        :load-text="loadText"
      />
    </view>

    <!-- <view class="item">
      <span class="item-one">2019.10.09 11:18:27</span>
      <span class="item-two">9878.00</span>
    </view>
    <view class="item">
      <span class="item-one">2019.10.09 11:18:27</span>
      <span class="item-two">9878.00</span>
    </view>
    <view class="item">
      <span class="item-one">2019.10.09 11:18:27</span>
      <span class="item-two">9878.00</span>
    </view> -->
  </view>
</template>

<script lang='ts' >
import { Component, Prop, Vue, Watch, Emit } from "vue-property-decorator";

import { profitDetails, profitDetailsSum } from "../../../utils/uniApi";

import uNavbar from "../../../uview-ui/components/u-navbar/u-navbar.vue";

import uSelect from "../../../uview-ui/components/u-select/u-select.vue";

import timeTest from "../../../views/test/timeTest.vue";

@Component({
  //   @Component  是一个装修器   不可以在下面写语句
  name: "test",
  components: {
    "u-navbar": uNavbar,
    "u-select": uSelect,

    timeTest,
  },
})
export default class extends Vue {
  @Prop({
    type: String, // 父组件传递给子组件的数据类型
    required: false, // 是否必填
    default: " ", // 默认值， 如果传入的是 Object，则要 default: ()=>({}) 参数为函数
  })
  msg!: string;

  public showDatas: any = [];

  public dateTime = "";
  public dateType = "month";

  public selectTime = "";

  public pageData = 1;

  public proily = "";

  //加载
  public status = "nomore";
  public loadText = {
    loadmore: "轻轻上拉",
    loading: "努力加载中",
    nomore: "暂无更多数据",
  };

  public loadmoreModal = true;

  public continueTypes = true;

  created() {}

  mounted() {
    //  console.log('父组件传递的参数:',this.$parent)   //暂时不考虑
    //  uni.navigateTo({
    // url: './selectBusin'
    // });

    this.profitDetailsSumM();

    // this.profitDetailsM();

    this.nowDate();
  }

  nowDate() {
    let datas = new Date();
    function formatDate(datas: any) {
      var myyear = datas.getFullYear();
      var mymonth = datas.getMonth() + 1;
      var myweekday = datas.getDate();

      if (mymonth < 10) {
        mymonth = "0" + mymonth;
      }
      if (myweekday < 10) {
        myweekday = "0" + myweekday;
      }
      return myyear + "-" + mymonth + "-" + myweekday;
    }

    console.log(formatDate(datas), "日期日期日期");

    this.selectTime =
      formatDate(datas).split("-")[0] + "-" + formatDate(datas).split("-")[1];

    // this.$emit('func',this.selectTime,'month')
  }
  getMsgFormSon(data: any, timeType: string) {
    // alert('999')
    console.log("子组件的数据", data, timeType);
    this.dateType = timeType;
    this.dateTime = data;
    this.profitDetailsM();

  }

  onReachBottom() {
    this.pageData = this.pageData + 1;
    this.profitDetailsM();
  }

  profitDetailsSumM() {

    let params = {
      userId:
        uni.getStorageSync("userId") == ""
          ? ""
          : parseInt(uni.getStorageSync("userId")), //代理ID 或 商户ID
      dateTime: this.dateTime, //查询时间（格式：2020-10-1 或 2020-10）
      dateType: this.dateType, //(month 按月查询,day 按天查询)
      userType: uni.getStorageSync("otherData").porxyShop=='porxy'?'0':'1', //("0" user ,"1" shop)
    };

    profitDetailsSum(params).then((res: any) => {
      console.log(res, "qweqwedasdas");

           this.proily = res.data.data;
    });
  }

  onPullDownRefresh() {
    console.log("refresh");

    setTimeout(function () {
      uni.redirectTo({
        url: "./index",
      });
      uni.stopPullDownRefresh();
    }, 1000);
  }

  profitDetailsM() {
    let params = {
      userId:
        uni.getStorageSync("userId") == ""
          ? ""
          : parseInt(uni.getStorageSync("userId")), //代理ID 或 商户ID
      dateTime: this.dateTime, //查询时间（格式：2020-10-1 或 2020-10）
      dateType: this.dateType, //(month 按月查询,day 按天查询)
      userType: "0", //	("0" user ,"1" shop)
      pageNo: this.pageData,
      pageSize: "10",
    };

    profitDetails(params).then((res: any) => {
      console.log(res, "列表数据");

      // this.showDatas=res.data.data

      if (res.data.data == null) {
        uni.showToast({
          title: "请求数据失败",
          icon: "none",
          duration: 2000,
        });
      } else {
        var boolee = res.data.hasNext == false && this.continueTypes == false;

        if (res.data.hasNext == true) {
          this.status = "loadmore";
        } else {
          this.status = "nomore";
        }

        console.log(res.data.hasNext, this.continueTypes, boolee);

        if (res.data.isFirst || !boolee) {
          res.data.data.filter((item: any, index: number) => {
            this.showDatas.push(item);

            if (res.data.hasNext == false) {
              this.continueTypes = false;
            }
          });

          uni.hideLoading();
        } else {
          // alert("加载完毕");
        }
      }
    });
  }
}
</script>

<style  lang="scss"  scoped>
/deep/.u-empty {
  height: 10rem;
}

uni-page-body {
  height: 100%;
}
.definite {
  font-family: PingFang SC;
  height: 100%;
}
.image {
  text-align: center;
  color: #000000;
  font-size: 0.8rem;
  font-weight: 400;
  font-family: PingFang SC;
  margin-bottom: 1rem;
}
.image image {
  width: 0.7rem;
  height: 0.7rem;
  padding-right: 0.4rem;
}
.money {
  color: #02af74;
  font-size: 0.9rem;
  text-align: center;
  font-weight: bold;
  font-family: PingFang SC;
  margin-bottom: 0.8rem;
}
.time {
  font-size: 0.7rem;
  text-align: center;
  font-family: PingFang SC;
  font-weight: 400;
  color: #666666;
}
.record {
  padding: 0.3rem 0.8rem;
  font-size: 0.65rem;
  font-family: PingFang SC;
  font-weight: 400;
  color: #000000;
  background: #f3f5f7;
}
.item {
  padding: 0.8rem;
  background: #ffffff;
  border-bottom: 0.05rem #f3f5f7 solid;
}
.item-one {
  font-size: 0.7rem;
  font-family: PingFang SC;
  font-weight: 400;
  color: #000000;
  line-height: 1.06rem;
}
.item-two {
  float: right;
  font-size: 0.75rem;
  font-family: PingFang SC;
  font-weight: 300;
  color: #ff0000;
  line-height: 1.06rem;
}
</style>